package com.yike.user.controller;

import com.yike.common.api.ApiResult;
import com.yike.common.base.BaseController;
import com.yike.common.log.Module;
import com.yike.common.pagination.Paging;
import com.yike.user.param.*;
import com.yike.user.service.PlatformReportService;
import com.yike.user.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 平台数据管理
 *
 * @author Sakura
 * @since 2024-11-18
 */
@Slf4j
@RestController
@RequestMapping("/platform/report")
@Module("user")
@Api(value = "平台报表管理API", tags = {"平台报表管理"})
public class PlatformReportController extends BaseController {

    @Autowired
    private PlatformReportService platformReportService;

    @PostMapping("/getSalesReportList")
    @ApiOperation(value = "销售报表", response = SalesReportDataVo.class)
    public ApiResult<Paging<SalesReportDataVo>> getSalesReportList(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        Paging<SalesReportDataVo> paging = platformReportService.getSalesReportList(platformReportDataParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getSalesReportCount")
    @ApiOperation(value = "销售报表统计", response = SalesReportDataVo.class)
    public ApiResult<SalesReportDataVo> getSalesReportCount(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        SalesReportDataVo salesReportDataVo = platformReportService.getSalesReportCount(platformReportDataParam);
        return ApiResult.ok(salesReportDataVo);
    }

    @PostMapping("/exportSalesReport")
    @ApiOperation(value = "销售报表导出", response = SalesReportDataVo.class)
    public void exportSalesReport(HttpServletResponse response, @Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        platformReportService.exportSalesReport(response, platformReportDataParam);
    }

    @PostMapping("/getAgentReportList")
    @ApiOperation(value = "代理商报表", response = AgentReportDataVo.class)
    public ApiResult<Paging<AgentReportDataVo>> getAgentReportList(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        Paging<AgentReportDataVo> paging = platformReportService.getAgentReportList(platformReportDataParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getAgentReportCount")
    @ApiOperation(value = "代理商报表统计", response = AgentReportDataVo.class)
    public ApiResult<AgentReportDataVo> getAgentReportCount(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        AgentReportDataVo agentReportDataVo = platformReportService.getAgentReportCount(platformReportDataParam);
        return ApiResult.ok(agentReportDataVo);
    }

    @PostMapping("/exportAgentReport")
    @ApiOperation(value = "代理商报表导出", response = SalesReportDataVo.class)
    public void exportAgentReport(HttpServletResponse response, @Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        platformReportService.exportAgentReport(response, platformReportDataParam);
    }

    @PostMapping("/getFinanceReportList")
    @ApiOperation(value = "财务报表", response = FinanceReportDataVo.class)
    public ApiResult<Paging<FinanceReportDataVo>> getFinanceReportList(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        Paging<FinanceReportDataVo> paging = platformReportService.getFinanceReportList(platformReportDataParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/getFinanceReportCount")
    @ApiOperation(value = "财务报表统计", response = FinanceReportDataVo.class)
    public ApiResult<FinanceReportDataVo> getFinanceReportCount(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        FinanceReportDataVo financeReportDataVo = platformReportService.getFinanceReportCount(platformReportDataParam);
        return ApiResult.ok(financeReportDataVo);
    }

    @PostMapping("/exportFinanceReport")
    @ApiOperation(value = "财务报表导出", response = SalesReportDataVo.class)
    public void exportFinanceReport(HttpServletResponse response, @Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        platformReportService.exportFinanceReport(response, platformReportDataParam);
    }

    @PostMapping("/getSalesCategoryRankList")
    @ApiOperation(value = "销售排行（分类排行）", response = SalesRankDataVo.class)
    public ApiResult<Paging<SalesRankDataVo>> getSalesRankList(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        Paging<SalesRankDataVo> paging = platformReportService.getSalesCategoryRankList(platformReportDataParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/exportSalesCategoryRank")
    @ApiOperation(value = "销售排行导出（分类排行）", response = SalesReportDataVo.class)
    public void exportSalesCategoryRank(HttpServletResponse response, @Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        platformReportService.exportSalesCategoryRank(response, platformReportDataParam);
    }

    @PostMapping("/getSalesGoodsRankList")
    @ApiOperation(value = "销售排行（商品排行）", response = SalesRankDataVo.class)
    public ApiResult<Paging<SalesRankDataVo>> getSalesGoodsRankList(@Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        Paging<SalesRankDataVo> paging = platformReportService.getSalesGoodsRankList(platformReportDataParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/exportSalesGoodsRank")
    @ApiOperation(value = "销售排行导出（商品排行）", response = SalesReportDataVo.class)
    public void exportSalesGoodsRank(HttpServletResponse response, @Validated @RequestBody PlatformReportDataParam platformReportDataParam) throws Exception {
        platformReportService.exportSalesGoodsRank(response, platformReportDataParam);
    }

}

